Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
This dialog box has the following three tabs from which to choose settings: • General—Toolbar properties (a subset of those available in the Visual Basic Properties window) • Buttons—Button properties, adding and deleting buttons • Picture—Displaying images on buttons Figure 22.4 The Toolbar Control’s Property Pages dialog box. You will use the General and Buttons tabs for your project. Here are descriptions of the properties on the General tab; the settings needed for the current project are in parentheses: • AllowCustomize—Permits the user to customize the Toolbar at runtime (off). Customization involves double-clicking on the Toolbar to display the Customize Toolbar dialog box, which permits you to add and remove buttons and change their order. • ShowTips—Displays a ToolTip (programmer defined) if the mouse cursor rests on the button briefly (on). • Enabled—Same as for other Visual Basic controls—activates or deactivates the Toolbar (on). • Wrappable—Indicates whether the Toolbar buttons wrap to multiple rows, if needed, when the container window is resized (on). • MousePointer—Displays when the pointer is over the Toolbar (ccDefault). • ImageList—When displaying images on the buttons, the ImageList controls where the images are stored (none). • ButtonHeight and ButtonWidth—Show the size of the buttons, expressed in the ScaleMode units of the Toolbar’s container. The ButtonWidth property is automatically adjusted to match the longest label (Caption property) on a button (default settings). Before you get to the details of adding buttons to the Toolbar, you need to understand the relationship between a Toolbar control and its buttons. As mentioned previously, each button is represented by a Button object, and all the Button objects on a Toolbar are represented by the Buttons collection. The Buttons collection is a standard Collection object, which you have met several times already. Briefly, the Buttons collection is a 1-based group of indexed Button objects (1-based means that the first button has index 1 rather than 0, which is more common in some other parts of Visual Basic). In code, therefore, you can access individual buttons and the Buttons collection by using standard Visual Basic collection syntax. If your Toolbar is named Toolbar1, for example, you can create a type Button variable that points to a specific button in one of several ways. First, declare the variable:
    Dim btnX As Button
Then, retrieve a specific button by its index number:
    Set btnX = Toolbar1.Buttons(2)      ‘Second button on Toolbar
You can also reference a button by a unique key (such as the Button object’s Key property):
    Set btnX = Toolbar1.Buttons(“second”) ‘ If Key = “second”
You can also use the Item method:
    Set btnX = Toolbar1.Buttons.Item(2)
After you retrieve the desired button, you can set its properties; for example:
    btnX.Caption = “Close”
    btnX.Enabled = False
The Toolbar control provides a great deal of flexibility, including the ability to add and remove buttons at runtime. (Refer to the Visual Basic Help system for more details.) Note that Toolbar buttons can be used in two basic ways. One way is to initiate a process, similar to a Command Button control; the Save Project and Open Project buttons on the Toolbar in the Visual Basic development environment operate in this fashion. The second way is to turn on and off options, like the Lock Controls button on the Toolbar in the Visual Basic development environment. You determine how a Button operates by manipulating its properties. Back to the project: After setting the Toolbar control’s General properties, as previously described, click on the Buttons tab, shown in Figure 22.5. You will add three buttons to the Toolbar, for now. Here are the basic steps to follow for each button: 1. Click on Insert Button and a new button is inserted to the right of the current button (as indicated in the Index box). If no buttons exist, the new button becomes the first button at the left of the Toolbar. If necessary, use the left and right arrow buttons to make the appropriate button current, before clicking on the Insert button. Figure 22.5 The Buttons tab on the Toolbar control’s Property Pages dialog box. 2. Type the button’s caption in the Caption box. 3. Repeat Steps 1 and 2 for additional buttons, and then click on OK. While these are the minimum steps required to add a button to a Toolbar, the Button object offers several other useful properties: • Caption—The text displayed on the button. • Description—The button description displayed at runtime in the Customize Toolbar dialog box. • Key—A unique string that identifies the button. • Value—Whether the button is pressed (Value = 1) or unpressed (Value = 0). • Style—The button’s style (see Table 22.2). • PlaceholderWidth—The width of a button if its Style is set to PlaceHolder. • Tag—This property is not used by Visual Basic. It serves as a location for extra data (in string format) that your program can use in any manner that it requires (same as the Tag property of other controls). • ToolTipText—The text that is displayed next to the mouse cursor when it is placed on a button briefly (but only if the Toolbar’s ShowTips property is True). • Image—The index of the button’s image in the associated ImageList control. • Visible—Indicates whether the button is visible. If a button’s Visible property is False, buttons to the right move over to fill in the space where the button would be displayed if Visible = True. • Enabled—Indicates whether the button is active (can be clicked). • MixedState—Controls whether the button is displayed in the mixed state (grayed out). A mixed-state button can still be active (Enabled). Now, what about this Style property? A Button object can have one of six different styles. Clearly, some Button properties are not relevant for certain styles. The available styles, the defined constants available for setting them, and their descriptions are given in Table 22.2. Table 22.2 Available styles for a Button object.
Constant | Value | Description
--- | --- | ---
tbrDefault | 0 | (Default) Button. The button is a regular push button.
tbrCheck | 1 | Check. The button is a check button, which can be checked or unchecked.
tbrButtonGroup | 2 | ButtonGroup. All buttons with this style constitute a group. One, and only one, button in a group can be depressed at a given time; clicking on one button automatically “unclicks” the one that was depressed previously. A Toolbar can have only one group.
tbrSeparator | 3 | Separator. The button functions as a separator with a fixed width of eight pixels.
tbrPlaceholder | 4 | Placeholder. The button appears and functions like a separator but has a settable width. A “button” with this style can be used to place another control on a Toolbar. For example, to place a drop-down Text Box on a Toolbar, add a Button with the PlaceHolder style and adjust its width to the desired size. Then, place a Combo Box of the same width on the placeholder button.
tbrDropDown | 5 | Dropdown. Shows an arrow next to the button that, when clicked on, displays a programmer-defined drop-down menu of command choices.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.